<?php
class dbConn{
    
    var $host;
    var $db;

    function __construct($host, $name, $pwd, $db)
                {
        $this->host = $host;
        $this->db = $db;
        $this->name = $name;
        $this->db_pwd = $pwd;
        $this->link = @mysql_connect($this->host, $this->name, $this->db_pwd) or die("Cannot connect.". mysql_error());
        @mysql_select_db($this->db)
                or die("Invalid database name.");

    }

    function getLastInsert()
    {
        return @mysql_insert_id();
    }

    function query($query, $desc = '') {
        if(!session_id()) {
            session_start();
        }
        $res = mysql_query($query);
        if (!$res) {
            echo mysql_error() . " : " .$query;
            exit;
        }
        return $res;
    }

    function close()
    {
        @mysql_close($this->link);
    }

    function count($res)
    {
        return @mysql_num_rows($res);
    }

    function fetch($res)
    {
        return @mysql_fetch_assoc($res);
    }

    function convertAndStrip($str) {
        if(get_magic_quotes_gpc()) $str = stripslashes($str);

        $str = @mysql_real_escape_string($str);
        $cur_encoding = mb_detect_encoding($str) ;

        if($cur_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8")) {
            return $str;
        }

        return utf8_encode($str);
    }

}
?>